﻿using System;
using System.Net.Mime;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace WebServer
{
	/// <summary>
	/// Provides an interface structure for development of virtual Web-WebObject Elements
	/// </summary>
	public interface IWebObjectElement
	{
		/// <summary>
		/// Gets or Sets the WebObject instance that this WebObjectElement is attached to
		/// </summary>
		IWebObject Parent { get; set; }

		/// <summary>
		/// Gets or Sets the opening tag used by this WebObjectElement
		/// </summary>
		string OpenTag { get; set; }

		/// <summary>
		/// Gets or Sets the closing tag used by this WebObjectElement
		/// </summary>
		string CloseTag { get; set; }

		/// <summary>
		/// Gets or Sets the Name of this WebObjectElement
		/// </summary>
		string Name { get; set; }

		/// <summary>
		/// Gets or Sets the unique ID of this WebObjectElement
		/// </summary>
		string ID { get; set; }

		/// <summary>
		/// Gets a list of strings that form the structure of this WebObjectElement
		/// </summary>
		Dictionary<string, bool> Lines { get; }
		
		/// <summary>
		/// Gets or Sets the compiled Content code for this WebObjectElement
		/// </summary>
		string Content { get; set; }

		/// <summary>
		/// Adds an 'html' element to this WebObject
		/// </summary>
		/// <param name="html">HTML code</param>
		void AddHTML(string html);

		/// <summary>
		/// Adds an 'html' element to this WebObject with formatted code
		/// </summary>
		/// <param name="format">String format</param>
		/// <param name="args">Format arguments</param>
		void AddHTML(string format, params object[] args);

		/// <summary>
		/// Adds a 'text' element to this WebObject
		/// </summary>
		/// <param name="text">Plain text</param>
		void AddText(string text);

		/// <summary>
		/// Adds a 'text' element to this WebObject with formatting
		/// </summary>
		/// <param name="format">String format</param>
		/// <param name="args">Format arguments</param>
		void AddText(string format, params object[] args);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="b"></param>
		void AddByte(byte b);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="bytes"></param>
		void AddByte(byte[] bytes);

		/// <summary>
		/// Compiles all strings (Lines) associated with this WebObjectElement into a single Content string before being compiled into the parent WebObject
		/// </summary>
		/// <returns>Content of this WebObjectElement, compiled into a single string</returns>
		string Compile();

		/// <summary>
		/// Fired when this Element is compiled
		/// </summary>
		void OnCompile();

		/// <summary>
		/// Fired just before this WebObjectElement is compiled and determines whether this WebObjectElement should be Compiled
		/// </summary>
		/// <returns>Returns 'true' by default, can be overridden in a derived class to determine whether this WebObjectElement should be compiled or not</returns>
		bool OnBeforeCompile();

		/// <summary>
		/// Fired just after this WebObjectElement is successfully compiled
		/// </summary>
		void OnAfterCompile();
	}
}
